/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

/**
 * <p>Project: javaseapp - Img7
 * <p>Powered by webrx On 2021-08-16 08:46:51
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img7 {
    public static void main(String[] args) throws IOException {
        int w = 800;
        int h = 800;
        BufferedImage i = new BufferedImage(w, h, 2);
        Graphics2D g = i.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, w, h);

        g.setColor(Color.RED);
        // g.drawLine(0, 0, w, h);

        g.setStroke(new BasicStroke(3));
        g.setColor(Color.WHITE);
        for (int n = 0; n < 800; n++) {
            int x = n;
            n += 18;
            g.drawLine(x, 400, x + 5, 400);
        }

        g.drawOval(10, 20, 30, 30);

        g.drawRect(50, 50, 50, 50);

        g.drawArc(100, 100, 100, 100, 0, 180);

        Random rand = new Random();
        for (int n = 0; n < 50; n++) {
            g.setColor(new Color(255, 255, 255, 220));
            g.drawArc(rand.nextInt(w), rand.nextInt(h), rand.nextInt(w) + 20, rand.nextInt(h) + 20, rand.nextInt(360), rand.nextInt(360));
        }

        // 画曲线
        Point[] points = {new Point(0, 0), new Point(0, rand.nextInt(h)), new Point(w, rand.nextInt(h))

        };

        GeneralPath path = new GeneralPath();
        path.moveTo(points[0].x, points[0].y);
        for (int i2 = 0; i2 < points.length - 1; ++i2) {
            Point sp = points[i2];
            Point ep = points[i2 + 1];
            Point c1 = new Point((sp.x + ep.x) / 2, sp.y);
            Point c2 = new Point((sp.x + ep.x) / 2, ep.y);
            path.curveTo(c1.x, c1.y, c2.x, c2.y, ep.x, ep.y);
        }
        g.draw(path);


        for (int n = 0; n <= 355; n += 10) {
            g.drawArc(100, 200, 600, 300, n, 5);
        }

        int yy = 100;// y
        int hh = 100;// 高度
        int aa = 200;//
        // x
        for (int x = 10; x < w; x += 15) {
            int y = (int) (yy + hh * Math.sin(x * Math.PI / aa));
            //g.drawLine(x, (int) y, x, (int) y);
            g.fillOval(x, y, 6, 6);
        }

        g.dispose();
        ImageIO.write(i, "png", new File("c:/ok.png"));

        Runtime run = Runtime.getRuntime();
        run.exec("cmd /k start c:/ok.png");
    }
}
